﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxMenu;
using System.Xml;
using SGRapidForm.Permission.Service.Interface;
using SGRapidForm.Common;
using SGRapidForm.Permission.Entity;

namespace SGDemo.Permission
{
    public partial class DeptItem : System.Web.UI.Page
    {
        private IPermissionService _permissionService = ServiceProxyFactory.Create<IPermissionService>("permissionservice");

        protected void Page_Load(object sender, EventArgs e)
        {
            JSManager.RegAjax(Header, this.GetType().BaseType);
        }

        /// <summary>
        /// 菜单项绑定事件 - 实现操作权限控制
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void menuHeader_ItemDataBound(object sender, MenuItemEventArgs e)
        {
            IHierarchyData itemHierarchyData = (IHierarchyData)e.Item.DataItem;
            XmlElement element = (XmlElement)itemHierarchyData.Item;
        }

        /// <summary>
        /// 查询明细
        /// </summary>
        /// <param name="keyid"></param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public Dept GetByKeyid(string keyid)
        {
            return _permissionService.Dept_GetByKeyid(keyid);
        }

        /// <summary>
        /// 新增保存
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public bool SaveForAdd(Dept dept)
        {
            //加入Session等服务端信息
            dept.CreateName = "Creater";
            dept.CreateDate = System.DateTime.Now;
            return _permissionService.Dept_Add(dept);
        }

        /// <summary>
        /// 编辑保存
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public bool SaveForEdit(Dept dept)
        {
            //加入Session等服务端信息
            dept.ModifyName = "Editer";
            dept.ModifyDate = System.DateTime.Now;
            bool ret = _permissionService.Dept_Update(dept);
            return ret;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="keyid">用户Keyid</param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public bool Delete(string keyid)
        {
            return _permissionService.Dept_Delete(keyid);
        }
    }
}